﻿// ***********************************************************************
// Assembly         : OSS.Earth
// Author           : tian_
// Created          : 10-17-2019
//
// Last Modified By : tian_
// Last Modified On : 10-30-2019
// ***********************************************************************
// <copyright file="ContourMapTestCmd.cs" company="">
//     Copyright ©  2017
// </copyright>
// <summary></summary>
// ***********************************************************************
using OsgEarth;
using OsgEarth.Util;
using OSS.Earth.Utility;
using ZFGK.Addins;
using ZFGK.osgEarth.UI;
using ZFGK.OSG.Utility;

namespace OSS.Earth.Commands.TestCmds
{
    /// <summary>
    /// Class ContourMapTestCmd.
    /// </summary>
    /// <seealso cref="ZFGK.Addins.IExtendCommand" />
    class ContourMapTestCmd : IExtendCommand
    {
        /// <summary>
        /// Executes the specified command data.
        /// </summary>
        /// <param name="cmdData">The command data.</param>
        /// <param name="message">The message.</param>
        /// <returns>CmdResult.</returns>
        public CmdResult Execute(ExtendCmdData cmdData, ref string message)
        {
            var form = cmdData.ViewForm as OsgEarthViewForm;
            var osgEarthViewCtrl = form.OsgEarthViewCtrl;
            var actionUtility = osgEarthViewCtrl.ActionUtility;
            var osgEarthObj = osgEarthViewCtrl.OsgEarthObj;

            osgEarthObj.GUIEventHandler.DoOnce(() =>
            {
                var mapNode = osgEarthObj.MapNode;

                var map = mapNode.getMap();
                var layerNum = map.getNumLayers();
                for (int i = (int)layerNum - 1; i > -1; i--)
                {
                    var layer = map.getLayerAt((uint)i);
                    var elevationLayer = new ElevationLayer(layer);
                    if (!layer.IsValid || elevationLayer.IsValid)
                        continue;
                    map.removeLayer(layer);
                }

                mapNode.getTerrainEngine().addEffect(new ContourMap());
                return false;
            });

            return CmdResult.Succeed;
        }
    }
}
